package com.sztle.admodule.control.manager;

import android.text.TextUtils;

import com.sztle.admodule.outstatus.AppStatusProcessor;
import com.sztle.admodule.someutils.Utils;
import com.umeng.analytics.MobclickAgent;
import com.umeng.commonsdk.UMConfigure;
import com.umeng.umcrash.UMCrash;

public class UMengManager {
    public static boolean isUmInit = false;
    public static long processStartTime = 0;

    public static void initPreUm() {
        // SDK预初始化函数不会采集设备信息，也不会向友盟后台上报数据。
        // preInit预初始化函数耗时极少，不会影响App首次冷启动用户体验
        UMConfigure.preInit(Utils.getApp(), AppStatusProcessor.getAppParam().uMengAppKey, AppStatusProcessor.getChannel());
        MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.MANUAL);//人工统计
    }

    public static void init(){
        if(isUmInit){
            return;
        }
        isUmInit = true;
        UMCrash.enableKillProcessAfterCrash(false);
        UMConfigure.setLogEnabled(AppStatusProcessor.isDebug());
        UMConfigure.init(Utils.getApp(), AppStatusProcessor.getAppParam().uMengAppKey, AppStatusProcessor.getChannel(), UMConfigure.DEVICE_TYPE_PHONE, "");

    }
    public static void reportLog(String event) {
        if (TextUtils.isEmpty(event)) {
            return;
        }
        MobclickAgent.onEvent(Utils.getApp(), event);
    }


    public static void reportPageStart(String pageName) {
        if (TextUtils.isEmpty(pageName)) {
            return;
        }
        MobclickAgent.onPageStart(pageName);
    }

    public static void reportPageEnd(String pageName) {
        if (TextUtils.isEmpty(pageName)) {
            return;
        }
        MobclickAgent.onPageEnd(pageName);
    }

    public static void exitWithThis(){
        MobclickAgent.onKillProcess(Utils.getApp());
    }
}
